# Contributor: Holger Jaekel <holger.jaekel@gmx.de>
# Maintainer:
pkgname=aws-c-io
pkgver=0.13.32
pkgrel=0
pkgdesc="Module for the AWS SDK for C handling all IO and TLS work for application protocols"
url="https://github.com/awslabs/aws-c-io"
# s390x: aws-c-common
# ppc64le: fails tests
# arm*: fails a bunch of tests / segfaults
arch="all !armhf !armv7 !ppc64le !s390x"
license="Apache-2.0"
makedepends="
	aws-c-cal-dev
	aws-c-common-dev
	cmake
	openssl-dev
	s2n-tls-dev
	samurai
	"
subpackages="$pkgname-dev"
source="$pkgname-$pkgver.tar.gz::https://github.com/awslabs/aws-c-io/archive/refs/tags/v$pkgver.tar.gz"
options="net" # required for tests to make connections

case "$CARCH" in
aarch64)
	# broken on new networking builder setup
	options="$options !check"
	;;
esac

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	CFLAGS="$CFLAGS -flto=auto" \
	CXXFLAGS="$CXXFLAGS -flto=auto" \
	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=/usr/lib \
		-DBUILD_SHARED_LIBS=True \
		-DCMAKE_BUILD_TYPE=None \
		-DBUILD_TESTING="$(want_check && echo ON || echo OFF)" \
		$CMAKE_CROSSOPTS
	cmake --build build
}

check() {
	ctest --test-dir build --output-on-failure -j${JOBS:-2}
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

dev() {
	default_dev
	amove usr/lib/aws-c-io
}

sha512sums="
54f6ef23ab7fb65c9d1425d21d59daf1b13a50595f7f06c7d4f74bfb5941a7ddf0185ae3249b940473422c1880bb034c0610876c6e13ae499ccd2dcc888c1b23  aws-c-io-0.13.32.tar.gz
"
